package com.lysj.food.app.controller;

import com.lysj.admin.utils.spring.foundation.base.BaseContent;
import com.lysj.admin.utils.web.ParamUtil;
import com.lysj.admin.utils.web.Resp;
import com.lysj.food.food.service.FoodService;
import com.lysj.food.food.service.WeighFoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by wtl on 2019-03-26 15:28:03
 * @description 商户app菜品控制层
 */
@Slf4j
@RestController
@RequestMapping("/food/management/app")
public class AppFoodController extends BaseContent {

    @Resource
    private FoodService foodService;

    @Resource
    private WeighFoodService weighFoodService;


    /**
     * @author Created by wtl on 2019/3/26 17:37
     * @Description 获取菜品
     */
    @GetMapping("/get_store_food")
    public Resp getStoreFood(String storeId) {
        return new Resp().success(foodService.getStoreFoodList(storeId));
    }

    /**
     * @author Created by wtl on 2019/4/12 15:48
     * @Description 称重列表，待称重和已称重
     * @param storeId 门店id
     * @param type 1：待称重；2：已称重
     */
    @GetMapping("/weigh_food_list")
    public Resp weighFoodList(String storeId, Integer type) {
        if (ParamUtil.isBlank(storeId)) {
            return new Resp().error(Resp.Status.PARAM_ERROR,"门店id为空");
        }
        if (ParamUtil.isBlank(type)) {
            return new Resp().error(Resp.Status.PARAM_ERROR,"称重状态为空");
        }
        return new Resp().success(weighFoodService.getRepository().findByStoreIdAndType(storeId, type));
    }

    /**
     * @author Created by wtl on 2019/4/12 16:01
     * @Description 称重，将待称重的改成已称重，并设置总价，修改订单
     */
    @PostMapping("/weigh_food")
    public Resp weighFood(String id, String weight) {
        if (ParamUtil.isBlank(id)) {
            return new Resp().error(Resp.Status.PARAM_ERROR,"称重id为空");
        }
        if (ParamUtil.isBlank(weight)) {
            return new Resp().error(Resp.Status.PARAM_ERROR,"称重重量为空");
        }
        return new Resp().success(foodService.orderItemModify(id,weight));
    }

}
